package com.andrew.markov.process.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileArrayProvider {

	public static String[][] readTo2DArray(String path, int dimention)
			throws IOException {

		FileInputStream fstream = new FileInputStream(path);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		String strLine;
		int arraySize = dimention;
		String array[][] = new String[arraySize][];
		int index = 0;
		while ((strLine = br.readLine()) != null) {
			array[index] = strLine.split(" ");
			index++;
		}
		br.close();
		printAll(array);
		return array;
	}

	static void printAll(String array[][]) {

		for (int i = 0; i < array.length; i++) {

			if (array[i] != null) {
				for (int j = 0; j < array[i].length; j++) {
					System.out.print(array[i][j] + " ");
				}
				System.out.println(" ");
			}
		}

	}
}